import store from "../store";

const callServerIp = localStorage.getItem('call_server') === null ? '' : JSON.parse(localStorage.getItem('call_server')).ip;
const callServerPort = localStorage.getItem('call_server') === null ? '' : JSON.parse(localStorage.getItem('call_server')).port;
const deviceId = localStorage.getItem('deviceId');
const id = localStorage.getItem('id');

const Socket = () => {
    let socket;
        //let webSocketUrl = 'ws://192.168.110.88:8081/call/station/' + id+ '/' + deviceId;
        let webSocketUrl = 'ws://' + callServerIp + ":" + callServerPort + '/call/station/' + id + '/' + deviceId;
        //console.log(webSocketUrl+"==================")
        if ('WebSocket' in window && deviceId !== null) {
            socket = new WebSocket(webSocketUrl);
        } else if (deviceId === null) {
            return;
        } else {
            console.error('请检查浏览器是否支持websocket！');
        }

        //连接通信
        //socket.onmessage = onmessage

    return socket
}

export {
    Socket, deviceId
}
//
// export class Socket {
// }